package config

import (
	"gopkg.in/yaml.v3"
	"log"
	"os"
	"path/filepath"
)

type config struct {
	App struct {
		AppID     string `yaml:"appID"`
		AppSecret string `yaml:"appSecret"`
		Token     string `yaml:"token"`
	}
	Server struct {
		Host    string `yaml:"host"`
		Port    int    `yaml:"port"`
		Timeout struct {
			Read  int `yaml:"read"`
			Write int `yaml:"write"`
			Idle  int `yaml:"idle"`
		} `yaml:"timeout"`
		MaxHeader int `yaml:"maxHeader"`
	} `yaml:"server"`
	Log struct {
		Dir string
	}
	Anniversary struct {
		LoveDate string `yaml:"loveDate"`
	} `yaml:"anniversary"`
	Notice struct {
		Hour   int `yaml:"hour"`
		Minute int `yaml:"minute"`
	} `yaml:"notice"`
}

var Configs config

func InitConfig() {
	exePath, err := os.Executable()
	if err != nil {
		log.Fatalf("获取可执行文件路径失败: %v", err)
	}
	baseDir := filepath.Dir(exePath)
	configPath := filepath.Join(baseDir, "config.yaml")
	data, err := os.ReadFile(configPath)
	if err != nil {
		log.Fatalf("读取配置文件失败: %v", err)
	}
	err = yaml.Unmarshal(data, &Configs)
	if err != nil {
		log.Fatalf("解析配置文件失败: %v", err)
	}
	Configs.Log.Dir = filepath.Join(baseDir, "logs")
}
